﻿@using Dal.Models
@using Webdiyer.WebControls.Mvc
@model CHACTOR
@{
    Layout = null;
    ViewBag.Nav = 2;
    ViewBag.Menu = 0;
    int ti = 1;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    @Html.Partial("meta")
</head>
<body id="b_main">
    @Html.Partial("header")
    <!--/end #header-->
    <div id="wrapper">
        <!--holds pretty much everything-->
        <div id="content">
            @Html.Partial("nav")
            @using (Html.BeginForm("manage", "Tongxun", FormMethod.Get, new { @class = "broom_form", id = "form0", style = "margin-left: 30px;" }))
            {
                <input type="hidden" name="type" id="type" />
                <table border="0" cellspacing="0" summary="table" class="broom_table">
                    <tbody>
                        <tr class="odd">
                            <td>姓名
                                @Html.TextBoxFor(i => i.NAME, new { @class = "inputbox" })
                            </td>
                            <td>电话
                                @Html.TextBoxFor(i => i.PHONE, new { @class = "inputbox" })
                            </td>
                            <td>邮件
                                @Html.TextBoxFor(i => i.EMAIL, new { @class = "inputbox" })
                            </td>
                        </tr>
                        <tr class="even">
                            <td>地址
                                @Html.TextBoxFor(i => i.ADDRESS, new { @class = "inputbox" })
                            </td>
                            <td>分组
                                @Html.TextBoxFor(i => i.TEAM, new { @class = "inputbox" })
                            </td>
                            <td>
                                <input onclick="$('form').first().submit(); return false;" type="submit" name="search"
                                    value="搜索通讯录" />
                                <input onclick="$('form').first().attr('action','/tongxun/export').submit(); return false;" type="submit" name="search"
                                    value="导出查询的联系人" />
                            </td>
                        </tr>
                    </tbody>
                </table>
            }

            <br />
            <br />
            @using (Html.BeginForm("manage", "Tongxun", FormMethod.Post, new { @class = "broom_form", id = "form1", style = "margin-left: 30px;" }))
            {
                if (ViewBag.Record != null && ViewBag.Record.Count > 0)
                {
                <h4 class="titlebold">
                    <br />
                    搜索结果列表:共计@(ViewBag.RecordCount)项
                </h4>
                <table cellspacing="0" summary="table" class="broom_table">
                    <tbody>
                        <tr class="even titlebold">
                            <td colspan="7">
                                <input type="button" name="window" value="给选中的联系人发短信" />
                            </td>
                        </tr>
                        <tr class="odd titlebold">
                            <td>
                                <input type="checkbox" name="ckAll" onclick="changeCheck(this)" />全选
                            </td>
                            <td>姓名
                            </td>
                            <td>电话
                            </td>
                            <td>电子邮件
                            </td>
                            <td>地址
                            </td>
                            <td>分组
                            </td>
                            <td>操作
                            </td>
                        </tr>
                        @foreach (var entity in (List<CHACTOR>)ViewBag.Record)
                        {
                            <tr class="@((ti++) % 2 == 0 ? "odd" : "even")">
                                <td>
                                    <input type="checkbox" name="tongxun" value="@(entity.ID)"/>
                                </td>
                                <td>
                                    @entity.NAME
                                </td>
                                <td style="text-align: center">
                                    @entity.PHONE
                                </td>
                                <td style="text-align: center">
                                    @entity.EMAIL
                                </td>
                                <td style="text-align: center">
                                    @entity.ADDRESS
                                </td>
                                <td style="text-align: center">
                                    @entity.TEAM
                                </td>
                                <td style="text-align: center">
                                    <a href="javascript:deleteChactor(@(entity.ID))">删除</a>
                                </td>
                            </tr>
                        }

                    </tbody>
                </table>
                }
                else
                {
                <div class="container1">
                    <div class="notification error">
                        <a class="close" href="#"></a><em>
                            <img alt="" src="/assets/img/icons/cross_circle.png">未搜索到数据,请尝试其他搜索条件</em>
                    </div>
                </div>
                }
                <div id="demo-modal" style="display: none;">
                    <div style="margin: 20px; font-size: 16px;">
                        短信内容<br />
                        <br />
                        <textarea name="msg" style="width: 300px; height: 200px"></textarea>
                        <br />
                        <br />
                        <input type="button" onclick="send()" value="确认发送" />
                    </div>
                </div>
            }
        </div>
    </div>
    <div class="clear">
    </div>

    <script type="text/javascript">
        function send() {
            var tongxun = '';
            $("input[name='tongxun']").each(function (index, obj) {
                if ($(obj).attr("checked") == "checked" || $(obj).attr("checked") == true) {
                    tongxun += "," + $(obj).val();
                }
            });
            $.post("/msg/add", { msg: $("[name='msg']").val(), tongxun: tongxun },
                 function (data) {
                     if (data.result == true) {
                         alert('发送成功,请稍后至"短信记录"查看结果');
                     } else {
                         alert('发送失败,请检查是否选中了联系人');
                     }
                 }
            );
        }

        function deleteChactor(id) {
            if (confirm('确定要删除该联系人吗?该操作不可恢复')) {
                $.ajax(
                    {
                        url: "/tongxun/delete?id=" + id,
                        dataType: "json",
                        success: function (data) {
                            if (data.result == true) {
                                alert("删除成功");
                                window.location.reload();
                            }
                        }
                    });
            }
        }

        function changeCheck(obj) {
            $("input[name='tongxun']").attr("checked", $(obj).attr("checked"));
        }


        $(document).ready(function () {
            $('input[name="window"]').qtip(
                {
                    id: 'modal', // Since we're only creating one modal, give it an ID so we can style it
                    content: {
                        text: $('#demo-modal'),
                        title: {
                            text: '短信窗口',
                            button: true
                        }
                    },
                    position: {
                        my: 'center', // ...at the center of the viewport
                        at: 'center',
                        target: $(window)
                    },
                    show: {
                        event: 'click', // Show it on click...
                        solo: true, // ...and hide all other tooltips...
                        modal: false // ...and make it modal
                    },
                    hide: false,
                    style: 'qtip-light qtip-rounded'
                });
        });
    </script>
</body>
</html>
